package org.tang.springcloudvv.cxf.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.tang.springcloudvv.persistence.base.mapper.ProductMapper;
import org.tang.springcloudvv.persistence.base.model.Product;
import org.tang.springcloudvv.persistence.base.model.ProductExample;
import org.tang.springcloudvv.util.SnowflakeGenerateId;

import java.util.Date;
import java.util.List;

/**
 * <p><em>Created on 2021/12/23 4:43 下午</em></p>
 *
 * @author fuzhongtang
 * @since 1.0.1
 */
@Service
public class ProductService //implements IProductService
{
    @Autowired
    private ProductMapper productMapper;

    /**
     * 保存商品
     */
    //@Override
    @Transactional
    public int save(String name ,Integer price)
    {

        Product product = new Product();
        product.setId(SnowflakeGenerateId.getNextId());
        product.setName(name);
        product.setPrice(price);
        product.setCreateTime(new Date());
        return productMapper.insertSelective(product);
    }

    /**
     * 查询商品
     * @return
     */
    //@Override
    public List<Product> select()
    {
        ProductExample example = new ProductExample();
        example.createCriteria().andCreateTimeLessThan(new Date());
        return productMapper.selectByExample(example);
    }

}
